package com.xinrui.sunnyday.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.xinrui.sunnyday.dao.MemberDao;
import com.xinrui.sunnyday.pojo.Member;
import com.xinrui.sunnyday.service.MemberService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.ArrayList;
import java.util.List;

@Service(interfaceClass = MemberService.class)
public class MemberServiceImpl implements MemberService {
    @Autowired
    private MemberDao memberDao;

    @Override
    public Member findByTelephone(String telephone) {
        return memberDao.findByTelephone(telephone);
    }

    @Override
    public void add(Member member) {
        memberDao.add(member);
    }

    /**
     * 会员折线图
     * @param months
     * @return
     */
    @Override
    public List<Integer> getMemberReport(List<String> months) {
        //返回会员数量是int格式 需要定义集合接收返回
        List<Integer> memberCount = new ArrayList<>();
        //循环每一个月 拿到每一个月的数据
        for (int i = 0;i<months.size();i++){
            //获取到月份
            String month = months.get(i);
            //通过过去一年的每一个月拿到会员数量
            Integer count = memberDao.findMemberCountBeforeDate(month);
            memberCount.add(count);
        }
        return memberCount;
    }
}
